package map;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Justin Parker
 * @Date 2024/7/22 0022 14:11
 * @Version 1.0
 */
public class MapDemo01 {
    public static void main(String[] args) {
        //构建Map对象，用于存储Key/value键值对
        Map<String,Integer> map = new HashMap<>();
        Integer value = map.put("语文",90);
        System.out.println("被替换的值："+value);
         map.put("化学",90);
         map.put("数学",85);
         map.put("英语",95);
         System.out.println("所有键值对："+map);

         value = map.put("语文",100);
         System.out.println("被替换的值："+value);
         System.out.println("所有键值对："+map);

         boolean result = map.containsKey("语文");
         System.out.println("是否包含键："+result);

         result = map.isEmpty();
        System.out.println("是否为空："+result);

        Integer score = map.get("语文");
        System.out.println("语文成绩："+score);

        Integer score2 = map.remove("语文");
        System.out.println("被删除的键值对："+score2);

        System.out.println("所有键值对："+map);

        map.clear();
        System.out.println(map.size());

    }
}
